Python Parallel Programming Cookbook by 2015

Python Parallel Programming Cookbook by 2015

Author:2015
Language: eng
Format: epub, mobi
Publisher: Packt Publishing


In the main program, we execute the task that will be performed in a sequential mode:

if __name__ == "__main__": for item in number_list: evaluate_item(item)

Also, in a parallel mode, we will use the concurrent.futures module's pooling capability for a thread pool:

with concurrent.futures.ThreadPoolExecutor(max_workers=5)\ as executor: for item in number_list: executor.submit(evaluate_item, item)

The ThreadPoolExecutor executes the given task using one of its internally pooled threads. It manages five threads working on its pool. Each thread takes a job out from the pool and executes it. When the job is executed, it takes the next job to be processed from the thread pool.

When all the jobs are processed, the execution time is printed:

print ("Thread pool execution in " + \ str(time.clock() - start_time_1), "seconds")



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.